import { setLocal } from '@/util/storage'
export default {
  namespaced: true,
  state: () => ({
    token: '',
    online: false,
    name: ''
  }),
  getters: {
    get: state => key => state[key]
  },
  mutations: {
    set(state, { key, data }) {
      state[key] = data
    }
  },
  actions: {
    setToken({ commit }, data) {
      const key = 'token'
      commit('set', { key, data })
      setLocal('login/setToken', data)
    },
    setOnline({ commit }, data) {
      const key = 'online'
      commit('set', { key, data })
      setLocal('login/setOnline', data)
    },
    setName({ commit }, data) {
      const key = 'name'
      commit('set', { key, data })
      setLocal('login/setName', data)
    }
  }
}
